{include file="common/header"}
<link href="/static/admin/css/other.css" rel="stylesheet">
<style>.layui-layer{background:white;border:none;border-radius:6px;}.layui-layer-title{background:#f8f8f8;}.linput{outline-style:none;border:1px solid #ccc; border-radius:3px; padding: 13px 14px; width: 100%;font-size: 14px;font-weight: 700;font-family: "Microsoft soft";margin-bottom:20px;}.pbtn{text-align:center;width:100%;}.pbtn input{border:none;background:#1880ff;color:white;border-radius:6px;padding:5px 15px;}</style>
<main class="lyear-layout-content">
    <div class="container-fluid">
        <div class="row ant-menu-submenu">
            <div class="col-lg-10 col-b90">
                <div class="card right-card">
                    <div class="right-card-header card-header">
                        <h4>{:lang('plugin.market')}</h4>
                    </div>
                    <div class="card-toolbar clearfix">
                        <div class="example-box" id="choose-plugin-lists">
                            <a class="btn btn-default" href="https://www.69kz.com/all.html?category=plug" target="_blank" >{:lang('plugin.market')}</a>
							{if condition="$is_login eq 1"}
                            <button class="btn btn-default login" data-type="go">{:lang('plugin.market_login')}</button>
                            <span><a class="btn btn-default" href="{:lang('plugin.register')}" target="_blank">{:lang('plugin.register_zh')}</a></span>
                            <span><a class="btn btn-default" href="{:lang('plugin.sqjc_url')}" target="_blank">{:lang('plugin.sqjc')}</a></span>
                            {else/}
                                {if condition="$is_auth eq 2"}
                                <!--<button class="btn btn-default" data-type="go">{:lang('plugin.market_get')}</button>-->
                                <!--<span>{:lang('plugin.gwarn')}</span>-->
                                {else/}
                                <button class="btn btn-default apply" data-type="apply">{:lang('plugin.auth_url')}</button>
                                <span><a class="btn btn-default" href="{:lang('plugin.sqjc_url')}" target="_blank">{:lang('plugin.sqjc')}</a></span>
                                <span>{:lang('plugin.auth')}</span>
                                {/if}
                            {/if}
                            
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>{:lang('public.name')}</th>
                                        <th>{:lang('public.introduce')}</th>
                                        <th>{:lang('public.author')}</th>
                                        <th>{:lang('public.version')}</th>
                                        <th>{:lang('public.operation')}</th>
                                    </tr>
                                </thead>
                                <tbody id="plugin">
                                {if condition="$pcount neq 0"}
                                {volist name="plist" id="vo"}
                                {volist name="vo" id="voo"}
                                    <tr id="addons-{$voo->pid}" class="addonsTr">
                                        <td>{$voo->title}</td>
                                        <td>{if condition="$voo->description neq ''"}{$voo->description}{else/}无{/if}</td>
                                        <td>{$voo->author}</td>
                                        <td>{$voo->edition}</td>
                                        <td>
                                            <a class="btn btn-xs btn-default install" data-name="{$voo->pid}" data-url="{$voo->durl}">{:lang('plugin.market_install')}</a>
                                        </td>
                                    </tr>
                                {/volist}
                                {/volist}
                                {else/}
                                    <tr>
                                        <td colspan="5" align="center">{$msg}</td>
                                    </tr>
                                {/if}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
{include file="common/footer"}
<script>
    let IM_config = {
        pluginState: "{:adminUrl('admin/Plugins/plugin_state')}",
        pluginMarket: "{:adminUrl('admin/Plugins/plugin_market')}",
        pluginApply: "{:adminUrl('admin/Plugins/plugin_apply')}",
        pluginInstall: "{:adminUrl('admin/Plugins/plugin_install')}",
    };
</script>
<script type="text/javascript" src="/static/admin/js/addons.js"></script>
<script>
    $('#choose-plugin-lists .login').click(function() {
        var mylay = layer.open({
            type: 1,
            title: '插件平台登录',
            area: ['400px', '250px'], //宽高
            content: '<div><input type="text" id="plogin" class="linput" value="" placeholder="插件平台账号"/></div><div><input type="password" class="linput" id="ppwd" value="" placeholder="插件平台密码"/></div><div class="pbtn"><input type="button" onclick="plugpt()" value="登 录" /></div>'
        });
    });
    function plugpt(){
        if($('#plogin').val() == '' || $('#ppwd').val() == ''){
            we_im_msg('补全信息再登录');return false;
        }
        $.post(IM_config.pluginMarket,{plogin:$('#plogin').val(),ppwd:$('#ppwd').val()}, function(r) {
            we_im_msg(r.data);
            if (r.code == 200) {
                setTimeout(function() {
                    window.location.reload();
                },2000);
            }
        });
    }
    $('#choose-plugin-lists .apply').click(function() {
        var mylay = layer.open({
            type: 1,
            title: '域名授权',
            area: ['400px', '320px'], //宽高
            content: '<div><input type="text" id="rname" class="linput" value="<?php echo $_SERVER["HTTP_HOST"];?>"  readonly=""/></div><div><select class="linput" name="payway" id="payway"><option value="1">微信支付</option><option value="2">支付宝支付</option></select></div><div><input type="text" id="rprice" class="linput" value="￥{$price}"  readonly=""/></div><div class="pbtn"><input type="button" onclick="rapply()" value="申 请" /></div>'
        });
    });
    function rapply(){
        if($('#rname').val() == '' || $('#payway').val() == ''){
            we_im_msg('缺少必要参数');return false;
        }
        $.post(IM_config.pluginApply,{pay:$('#payway').val()}, function(r) {
            we_im_msg(r.data);
            if (r.code == 200) {
                setTimeout(function() {
                    window.location.reload();
                },2000);
            }
        });
    }
    $('.addonsTr .install').click(function() {
        var obj = $(this);
        var confirm = layer.confirm('确定要安装这个插件吗？', {
            btn: ['安装','取消']
        }, function(){
            var name = obj.attr('data-name');
            var url = obj.attr('data-url');
            $.post(IM_config.pluginInstall,{pid:name,url:url}, function(r) {
                we_im_msg(r.data);
                if (r.code == 400) {
                    addons_cache_delete();//删除插件缓存
                    setTimeout(function() {
                        window.location.reload();
                    },2000);
                }
                if (r.code == 200) {
                    addons_cache_delete();//删除插件缓存
                    setTimeout(function() {
                        window.location.href = r.url;
                    },2000);
                }
            });
        });
    });
</script>

